#include "aeRenderer.h"

//--------------------------------------------------------------------
ADERenderer::ADERenderer()
{
	m_pRenderTargetView	= NULL;
}

//--------------------------------------------------------------------
ADERenderer::~ADERenderer()
{
	if( m_pRenderTargetView )	m_pRenderTargetView->Release();
}

//--------------------------------------------------------------------
HRESULT ADERenderer::CreateRenderTargetView()
{
	HRESULT hr = S_OK;

	ID3D11Texture2D* pBackBuffer = NULL;
	hr = m_pDevice->GetSwapChain()->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer );
	if( FAILED( hr ) )
		return hr;

	hr = m_pDevice->GetDevice()->CreateRenderTargetView( pBackBuffer, NULL, &m_pRenderTargetView );
	pBackBuffer->Release();
	if( FAILED( hr ) )
		return hr;

	m_pDevice->GetDeviceContext()->OMSetRenderTargets( 1, &m_pRenderTargetView, NULL );

	return S_OK;
}

//--------------------------------------------------------------------
void ADERenderer::SetVIewPort( HWND hWnd )
{
	RECT rc;
	GetClientRect( hWnd, &rc );
	UINT width	= rc.right - rc.left;
	UINT height	= rc.bottom - rc.top;

	D3D11_VIEWPORT vp;
	vp.Width	= (FLOAT)width;
	vp.Height	= (FLOAT)height;
	vp.MinDepth	= 0.0f;
	vp.MaxDepth	= 1.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	m_pDevice->GetDeviceContext()->RSSetViewports( 1, &vp );
}

//--------------------------------------------------------------------
void ADERenderer::Render()
{
	float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f };
	m_pDevice->GetDeviceContext()->ClearRenderTargetView( m_pRenderTargetView, ClearColor );
	m_pDevice->GetSwapChain()->Present( 0, 0 );
}